<template>
  <div class="announcement-editor" v-reveal="{ delay: 60 }">
    <div class="container">
      <el-page-header @back="goBack" title="返回管理后台" class="page-header">
        <template #content>
          <span class="page-title">公告管理</span>
        </template>
      </el-page-header>
      
      <div class="editor-content" v-reveal="{ delay: 120 }">
        <el-row :gutter="24" class="main-row">
          <!-- 公告列表 - 左侧 -->
          <el-col :xs="24" :sm="24" :md="18" :lg="18" :xl="18">
            <el-card class="list-card" v-reveal="{ delay: 160, distance: 12 }">
              <template #header>
                <div class="card-header">
                  <h3>公告列表</h3>
                                     <el-button type="success" @click="addNewAnnouncement" size="small" class="add-btn">
                     <el-icon><Plus /></el-icon>
                     新建
                   </el-button>
                </div>
              </template>
              
              <div class="announcement-list">
                <div 
                  v-for="(announcement, idx) in announcements" 
                  :key="announcement.id"
                  class="announcement-item"
                  :class="{ active: selectedAnnouncement?.id === announcement.id }"
                  @click="selectAnnouncement(announcement)"
                  v-reveal="{ delay: 180 + idx * 40, distance: 8 }"
                >
                  <div class="announcement-image" v-if="announcement.imageUrl">
                    <img :src="announcement.imageUrl" :alt="announcement.title" />
                  </div>
                  <div class="announcement-content">
                    <div class="announcement-info">
                      <h4 class="announcement-title">{{ announcement.title }}</h4>
                      <p class="announcement-excerpt">{{ announcement.content.substring(0, 100) }}{{ announcement.content.length > 100 ? '...' : '' }}</p>
                      <div class="announcement-meta">
                        <span class="date">{{ announcement.date }}</span>
                        <span class="author" v-if="announcement.authorId">作者: {{ announcement.authorId }}</span>
                        <div class="tags" v-if="announcement.tags">
                          <el-tag size="small" type="info" class="rounded-tag">{{ announcement.tags }}</el-tag>
                        </div>
                      </div>
                    </div>
                                         <div class="announcement-actions">
                       <el-button type="primary" size="small" @click.stop="editAnnouncement(announcement)" class="action-btn edit-btn">
                         <el-icon><Edit /></el-icon>
                       </el-button>
                       <el-button type="danger" size="small" @click.stop="deleteAnnouncement(announcement.id)" class="action-btn delete-btn">
                         <el-icon><Delete /></el-icon>
                       </el-button>
                     </div>
                  </div>
                </div>
                
                <div v-if="announcements === null || announcements.length === 0" class="empty-state">
                  <el-empty description="暂无公告" />
                </div>
              </div>
              
              <!-- 分页组件 -->
              <div class="pagination-container" v-if="pagination.total > 0">
                <el-pagination
                  v-model:current-page="pagination.current"
                  v-model:page-size="pagination.size"
                  :page-sizes="[5, 10, 20, 50]"
                  :total="pagination.total"
                  layout="total, sizes, prev, pager, next, jumper"
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  background
                  class="rounded-pagination"
                />
              </div>
            </el-card>
          </el-col>
          
          <!-- 表单 - 右侧 -->
          <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
            <el-card class="form-card" v-reveal="{ delay: 200, distance: 12 }">
              <template #header>
                <div class="card-header">
                  <h2>{{ isEditing ? '编辑公告' : '添加公告' }}</h2>
                  <div class="header-actions">
                                         <el-button @click="addNewAnnouncement" v-if="isEditing" class="form-btn">
                       新建
                     </el-button>
                     <el-button type="primary" @click="saveAnnouncement" :loading="saving" class="form-btn save-btn">
                       <el-icon><Check /></el-icon>
                       {{ isEditing ? '更新' : '保存' }}
                     </el-button>
                  </div>
                </div>
              </template>
              
              <el-form :model="announcementForm" :rules="formRules" ref="formRef" label-width="80px" class="compact-form">
                <el-form-item label="标题" prop="title">
                  <el-input v-model="announcementForm.title" placeholder="请输入公告标题" class="rounded-input" />
                </el-form-item>
                
                <el-form-item label="作者" prop="authorId">
                  <el-input v-model="announcementForm.authorId" placeholder="作者ID（可选）" class="rounded-input" />
                </el-form-item>
                
                <el-form-item label="标签" prop="tags">
                  <el-input v-model="announcementForm.tags" placeholder="标签，逗号分隔" class="rounded-input" />
                </el-form-item>
                
                <el-form-item label="Slug" prop="slug">
                  <el-input v-model="announcementForm.slug" placeholder="URL Slug（可选）" class="rounded-input" />
                </el-form-item>
                
                <el-form-item label="内容" prop="content">
                  <el-input
                    v-model="announcementForm.content"
                    type="textarea"
                    :rows="6"
                    placeholder="请输入公告内容"
                    class="rounded-textarea"
                  />
                </el-form-item>
                
                <el-form-item label="封面图" prop="imageUrl">
                  <el-upload
                    class="image-uploader"
                    :show-file-list="false"
                    :on-success="handleImageSuccess"
                    :before-upload="beforeImageUpload"
                    action="#"
                    :http-request="customUpload"
                  >
                    <img v-if="announcementForm.imageUrl" :src="announcementForm.imageUrl" class="uploaded-image" />
                    <el-icon v-else class="image-uploader-icon"><Plus /></el-icon>
                  </el-upload>
                </el-form-item>
                
                <el-form-item label="媒体文件" prop="mediaFiles">
                  <el-upload
                    class="media-uploader"
                    :file-list="mediaFileList"
                    :on-remove="handleMediaRemove"
                    :on-success="handleMediaSuccess"
                    :before-upload="beforeMediaUpload"
                    action="#"
                    :http-request="customMediaUpload"
                    multiple
                  >
                                         <el-button type="primary" class="upload-btn">
                       <el-icon><Upload /></el-icon>
                       上传文件
                     </el-button>
                  </el-upload>
                </el-form-item>
              </el-form>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getNewsData } from '../api/serverApi'
import { Plus, Edit, Delete, Check, Upload } from '@element-plus/icons-vue'
import axiosInstance from '../interceptors'

export default {
  name: 'AnnouncementEditor',
  components: {
    Plus,
    Edit,
    Delete,
    Check,
    Upload
  },
  setup() {
    const router = useRouter()
    const formRef = ref()
    const announcements = ref([])
    const selectedAnnouncement = ref(null)
    const isEditing = ref(false)
    const saving = ref(false)
    
    // 分页状态
    const pagination = ref({
      current: 1,
      size: 10,
      total: 0,
      pages: 0
    })
    
    const announcementForm = ref({
      id: null,
      title: '',
      content: '',
      authorId: '',
      tags: '',
      slug: '',
      imageUrl: '',
    })
    const mediaFiles = ref([])
    const mediaFilesInput = ref('')
    
    // 媒体文件列表
    const mediaFileList = computed(() => {
      return mediaFiles.value.map((file, index) => ({
        name: file.name || `文件${index + 1}`,
        url: file.url || file
      }))
    })
    
    const formRules = {
      title: [
        { required: true, message: '请输入公告标题', trigger: 'blur' }
      ],
      content: [
        { required: true, message: '请输入公告内容', trigger: 'blur' }
      ]
    }
    
    const goBack = () => {
      router.push('/admin')
    }
    
    const loadAnnouncements = async (pageNum = 1, pageSize = 10) => {
      try {
        const res = await axiosInstance.get(`/announcement/page/${pageNum}/size/${pageSize}`)
        if(res.data.code === "1"){
          announcements.value = res.data.data.records
          announcements.value.forEach(item => {
            
            item.mediaUrls = item.mediaUrls.replace('\\"', '/')
            // console.log(item.mediaUrls)
            item.mediaUrls = JSON.parse(item.mediaUrls)
    
            })
          
          
         
          pagination.value = {
            current: res.data.data.current,
            size: res.data.data.size,
            total: res.data.data.total,
            pages: res.data.data.pages
          }
        } else {
          ElMessage.error(res.data.message || '加载失败')
        }
      } catch (error) {
        console.error('加载公告失败:', error)
        // 添加模拟数据用于测试滚动
        const mockData = []
        for (let i = 1; i <= 20; i++) {
          mockData.push({
            id: i,
            title: `测试公告 ${i}`,
            content: `这是第 ${i} 条测试公告的内容，用于测试滚动功能是否正常工作。内容比较长，确保能够触发滚动条显示。`,
            authorId: `作者${i}`,
            tags: `标签${i}`,
            date: new Date().toISOString().split('T')[0],
            imageUrl: `https://picsum.photos/120/80?random=${i}`,
            mediaFiles: []
          })
        }
        announcements.value = mockData
        pagination.value = {
          current: pageNum,
          size: pageSize,
          total: 20,
          pages: Math.ceil(20 / pageSize)
        }
        ElMessage.warning('使用模拟数据，API连接失败')
      }
    }
    
    // 处理页码变化
    const handleCurrentChange = (page) => {
      pagination.value.current = page
      loadAnnouncements(page, pagination.value.size)
    }
    
    // 处理每页数量变化
    const handleSizeChange = (size) => {
      pagination.value.size = size
      pagination.value.current = 1 // 重置到第一页
      loadAnnouncements(1, size)
    }
    
    const addNewAnnouncement = () => {
      isEditing.value = false
      selectedAnnouncement.value = null
      announcementForm.value = {
        id: null,
        title: '',
        content: '',
        authorId: '',
        tags: '',
        slug: '',
        date: new Date().toISOString().split('T')[0],
        imageUrl: '',
        link: ''
      }
      mediaFiles.value = []
      mediaFilesInput.value = ''
    }
    
    const selectAnnouncement = (announcement) => {
      selectedAnnouncement.value = announcement
    }
    
    const editAnnouncement = (announcement) => {
      isEditing.value = true
      selectedAnnouncement.value = announcement
      announcementForm.value = { ...announcement }
      // 将数组媒体字段展示为文件列表
      if (Array.isArray(announcement.mediaFiles)) {
        mediaFiles.value = announcement.mediaFiles.map(url => ({ url, name: url.split('/').pop() }))
      } else {
        mediaFiles.value = []
      }
    }
    
    const deleteAnnouncement = async (id) => {
      try {
        await ElMessageBox.confirm('确定要删除这条公告吗？', '确认删除', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        
        // 临时处理：从本地数组中移除
        announcements.value = announcements.value.filter(item => item.id !== id)
        if (selectedAnnouncement.value?.id === id) {
          selectedAnnouncement.value = null
          addNewAnnouncement()
        }
        
        ElMessage.success('公告删除成功')
      } catch (error) {
        // 用户取消删除
      }
    }
    
    // 图片上传处理
    const handleImageSuccess = (response, file) => {
      announcementForm.value.imageUrl = URL.createObjectURL(file.raw)
    }
    
    const beforeImageUpload = (file) => {
      const isImage = file.type.startsWith('image/')
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isImage) {
        ElMessage.error('只能上传图片文件!')
        return false
      }
      if (!isLt2M) {
        ElMessage.error('图片大小不能超过 2MB!')
        return false
      }
      return true
    }
    
    const customUpload = (options) => {
      // 这里应该调用真实的上传API
      const reader = new FileReader()
      reader.readAsDataURL(options.file)
      reader.onload = () => {
        announcementForm.value.imageUrl = reader.result
        options.onSuccess()
      }
    }
    
    // 媒体文件上传处理
    const handleMediaSuccess = (response, file) => {
      mediaFiles.value.push({
        name: file.name,
        url: URL.createObjectURL(file.raw)
      })
    }
    
    const handleMediaRemove = (file) => {
      const index = mediaFiles.value.findIndex(item => item.url === file.url)
      if (index > -1) {
        mediaFiles.value.splice(index, 1)
      }
    }
    
    const beforeMediaUpload = (file) => {
      const isLt10M = file.size / 1024 / 1024 < 10
      if (!isLt10M) {
        ElMessage.error('文件大小不能超过 10MB!')
        return false
      }
      return true
    }
    
    const customMediaUpload = (options) => {
      // 这里应该调用真实的上传API
      const reader = new FileReader()
      reader.readAsDataURL(options.file)
      reader.onload = () => {
        mediaFiles.value.push({
          name: options.file.name,
          url: reader.result
        })
        options.onSuccess()
      }
    }
    
    const saveAnnouncement = async () => {
      if (!formRef.value) return
      
      try {
        await formRef.value.validate()
        saving.value = true
        
        // 将媒体文件数组转换为URL数组
        const mediaUrls = mediaFiles.value.map(file => file.url)

        const toSave = { 
          ...announcementForm.value, 
          mediaFiles: mediaUrls 
        }

        if (isEditing.value) {
          // 临时处理：更新本地数组
          const index = announcements.value.findIndex(item => item.id === announcementForm.value.id)
          if (index !== -1) {
            announcements.value[index] = toSave
          }
          ElMessage.success('公告更新成功')
        } else {
          // 临时处理：添加到本地数组
          announcements.value.unshift(toSave)
          ElMessage.success('公告添加成功')
        }
        
        // 重置表单
        addNewAnnouncement()
      } catch (error) {
        console.error('保存失败:', error)
      } finally {
        saving.value = false
      }
    }
    
    onMounted(() => {
      loadAnnouncements()
      addNewAnnouncement()
    })
    
    return {
      formRef,
      announcements,
      selectedAnnouncement,
      isEditing,
      saving,
      pagination,
      announcementForm,
      mediaFilesInput,
      mediaFileList,
      formRules,
      goBack,
      loadAnnouncements,
      handleCurrentChange,
      handleSizeChange,
      addNewAnnouncement,
      selectAnnouncement,
      editAnnouncement,
      deleteAnnouncement,
      handleImageSuccess,
      beforeImageUpload,
      customUpload,
      handleMediaSuccess,
      handleMediaRemove,
      beforeMediaUpload,
      customMediaUpload,
      saveAnnouncement
    }
  }
}
</script>

<style scoped>
.announcement-editor {
  padding: 0;
  min-height: 100vh;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 中等屏幕下的滚动优化 */
@media (min-width: 570px) and (max-width: 985px) {
  .announcement-editor {
    overflow: auto;
  }
}

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* 中等屏幕下的容器优化 */
@media (min-width: 570px) and (max-width: 985px) {
  .container {
    height: auto;
    min-height: 100vh;
  }
}

.page-header {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 0;
  padding: 15px 20px;
  margin: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: #4CAF50;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.editor-content {
  flex: 1;
  padding: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 中等屏幕下的编辑内容优化 */
@media (min-width: 570px) and (max-width: 985px) {
  .editor-content {
    flex: none;
    overflow: visible;
    padding: 15px;
  }
}

.main-row {
  height: 100%;
  margin: 0;
}

/* 中等屏幕下的主行优化 */
@media (min-width: 570px) and (max-width: 985px) {
  .main-row {
    height: auto;
    margin: 0;
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  color: #4CAF50;
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.card-header h3 {
  color: #333;
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-direction: column;
}

.list-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.form-card {
  height: 100%;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.announcement-list {
  flex: 1;
  overflow-y: auto !important;
  overflow-x: hidden;
  padding-right: 10px;
  margin-bottom: 20px;
  min-height: 0;
  height: 100%;
}

.announcement-list::-webkit-scrollbar {
  width: 8px;
}

.announcement-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.announcement-list::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.announcement-list::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.announcement-item {
  display: flex;
  align-items: flex-start;
  padding: 20px;
  border: 2px solid #f0f0f0;
  border-radius: 16px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.announcement-item:hover {
  border-color: #4CAF50;
  background: #f8fff8;
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(76, 175, 80, 0.15);
}

.announcement-item.active {
  border-color: #4CAF50;
  background: linear-gradient(135deg, #e8f5e8 0%, #f0f9f0 100%);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(76, 175, 80, 0.2);
}

.announcement-image {
  flex-shrink: 0;
  width: 120px;
  height: 80px;
  margin-right: 20px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.announcement-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.announcement-content {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 15px;
}

.announcement-info {
  flex: 1;
  min-width: 0;
}

.announcement-title {
  margin: 0 0 8px 0;
  color: #333;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.announcement-excerpt {
  margin: 0 0 12px 0;
  color: #666;
  font-size: 0.95rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.announcement-meta {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.date {
  color: #999;
  font-size: 0.85rem;
  font-weight: 500;
}

.author {
  color: #666;
  font-size: 0.85rem;
  font-weight: 500;
}

.tags {
  display: flex;
  gap: 5px;
}

.rounded-tag {
  border-radius: 20px;
  font-weight: 500;
}

.announcement-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: center;
  justify-content: flex-end;
  min-width: 90px;
  position: relative;
}

/* 新建按钮样式 */
.add-btn {
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  border: none;
  border-radius: 12px;
  color: white;
  font-weight: 600;
  padding: 8px 16px;
  height: 36px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.add-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(76, 175, 80, 0.4);
  background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
}

.add-btn .el-icon {
  font-size: 16px;
}

/* 操作按钮样式 */
.action-btn {
  border: none;
  border-radius: 10px;
  font-weight: 600;
  height: 32px;
  width: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  position: relative;
}

.edit-btn {
  background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
  color: white;
}

.edit-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 16px rgba(33, 150, 243, 0.3);
  background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
}

.delete-btn {
  background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
  color: white;
}

.delete-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 16px rgba(244, 67, 54, 0.3);
  background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
}

.action-btn .el-icon {
  font-size: 14px;
}

.form-btn .el-icon,
.upload-btn .el-icon {
  font-size: 14px;
}

/* 表单按钮样式 */
.form-btn {
  border: none;
  border-radius: 10px;
  font-weight: 600;
  padding: 8px 16px;
  height: 36px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.save-btn {
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  color: white;
}

.save-btn:hover {
  background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.3);
}

/* 上传按钮样式 */
.upload-btn {
  background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%);
  border: none;
  border-radius: 10px;
  color: white;
  font-weight: 600;
  padding: 8px 16px;
  height: 36px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(156, 39, 176, 0.3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.upload-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(156, 39, 176, 0.4);
  background: linear-gradient(135deg, #7B1FA2 0%, #6A1B9A 100%);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
}

/* 分页容器样式 */
.pagination-container {
  padding: 20px 0;
  border-top: 1px solid #f0f0f0;
  background: white;
  border-radius: 0 0 16px 16px;
  position: sticky;
  bottom: 0;
  z-index: 10;
  flex-shrink: 0;
  margin-top: auto;
}

.rounded-pagination {
  justify-content: center;
  padding: 0 20px;
}

.rounded-pagination .el-pagination .btn-prev,
.rounded-pagination .el-pagination .btn-next,
.rounded-pagination .el-pagination .el-pager li {
  border-radius: 20px;
  margin: 0 2px;
}

/* 表单样式优化 */
.compact-form {
  font-size: 0.9rem;
}

.compact-form .el-form-item {
  margin-bottom: 16px;
}

.compact-form .el-form-item__label {
  font-weight: 600;
  color: #333;
}

.rounded-input .el-input__wrapper,
.rounded-textarea .el-textarea__inner {
  border-radius: 12px;
  transition: all 0.3s ease;
  border: 2px solid #f0f0f0;
}

.rounded-input .el-input__wrapper:hover,
.rounded-textarea .el-textarea__inner:hover {
  border-color: #4CAF50;
}

.rounded-input .el-input__wrapper.is-focus,
.rounded-textarea .el-textarea__inner:focus {
  border-color: #4CAF50;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

/* 图片上传样式 */
.image-uploader {
  text-align: center;
}

.image-uploader .el-upload {
  border: 2px dashed #d9d9d9;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  width: 100%;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-uploader .el-upload:hover {
  border-color: #4CAF50;
  background: #f8fff8;
}

.image-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.uploaded-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}

/* 媒体文件上传样式 */
.media-uploader {
  width: 100%;
}

.media-uploader .el-upload-list {
  margin-top: 10px;
}

.media-uploader .el-upload-list__item {
  border-radius: 8px;
  margin-bottom: 8px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .editor-content {
    padding: 15px;
  }
  
  .list-card,
  .form-card {
    height: auto;
    min-height: 400px;
  }
  
  .announcement-list {
    max-height: 500px;
    overflow-y: auto;
  }
  
  .announcement-item {
    flex-direction: column;
  }
  
  .announcement-image {
    width: 100%;
    height: 200px;
    margin-right: 0;
    margin-bottom: 15px;
  }
  
  .announcement-content {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
  
  .announcement-info {
    margin-bottom: 0;
  }
  
  .announcement-actions {
    align-self: flex-end;
    justify-content: center;
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    min-width: auto;
  }
}

/* 中等屏幕特殊优化 (570px - 985px) */
@media (min-width: 570px) and (max-width: 985px) {
  .announcement-editor {
    height: 100vh;
    overflow: auto;
  }
  
  .container {
    height: auto;
    min-height: 100vh;
  }
  
  .editor-content {
    padding: 15px;
    flex: none;
    overflow: visible;
  }
  
  .main-row {
    height: auto;
    margin: 0;
  }
  
  .main-row .el-col {
    margin-bottom: 20px;
  }
  
  .list-card,
  .form-card {
    height: auto;
    min-height: 300px;
    max-height: none;
  }
  
  .announcement-list {
    max-height: 400px;
    overflow-y: auto;
  }
  
  .form-card {
    overflow-y: visible;
  }
  
  .compact-form {
    padding-bottom: 20px;
  }
  
  /* 确保表单完全可见 */
  .form-card .el-card__body {
    padding: 20px;
    overflow: visible;
  }
  
  .compact-form .el-form-item {
    margin-bottom: 20px;
  }
  
  /* 调整按钮大小 */
  .add-btn,
  .form-btn,
  .upload-btn {
    height: 36px;
    padding: 8px 16px;
    font-size: 0.9rem;
  }
  
  .action-btn {
    height: 32px;
    width: 32px;
  }
  
  /* 修复操作按钮布局 */
  .announcement-item {
    position: relative;
  }
  
  .announcement-actions {
    position: absolute;
    top: 20px;
    right: 20px;
    justify-content: flex-end;
    gap: 8px;
    min-width: 70px;
    flex-shrink: 0;
    width: auto;
    align-self: auto;
    flex-direction: row;
    align-items: center;
  }
  
  .announcement-content {
    padding-right: 90px;
    min-height: 120px;
  }
  
  .action-btn {
    height: 30px;
    width: 30px;
    flex-shrink: 0;
  }
  
  .action-btn .el-icon {
    font-size: 13px;
  }
}

/* 中等屏幕优化 (570px - 1200px) */
@media (min-width: 570px) and (max-width: 1200px) {
  .announcement-editor {
    height: 100vh;
    overflow: auto;
  }
  
  .editor-content {
    padding: 15px;
    flex: none;
  }
  
  .main-row {
    margin: 0;
  }
  
  .main-row .el-col {
    margin-bottom: 15px;
  }
  
  .list-card,
  .form-card {
    height: auto;
    min-height: 400px;
  }
  
  .announcement-list {
    max-height: 500px;
    overflow-y: auto;
  }
  
  .announcement-item {
    flex-direction: column;
    position: relative;
  }
  
  .announcement-image {
    width: 100%;
    height: 200px;
    margin-right: 0;
    margin-bottom: 15px;
  }
  
  .announcement-content {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    min-height: 120px;
    padding-right: 0;
  }
  
  .announcement-info {
    margin-bottom: 0;
    flex: 1;
    min-width: 0;
  }
  
  .announcement-actions {
    align-self: flex-end;
    justify-content: center;
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    min-width: auto;
    position: static;
    top: auto;
    right: auto;
  }
  
  .action-btn {
    height: 30px;
    width: 30px;
    flex-shrink: 0;
  }
  
  .action-btn .el-icon {
    font-size: 13px;
  }
  
  .add-btn,
  .form-btn,
  .upload-btn {
    height: 34px;
    padding: 7px 14px;
    font-size: 0.85rem;
    flex-shrink: 0;
  }
  
  .add-btn .el-icon,
  .form-btn .el-icon,
  .upload-btn .el-icon {
    font-size: 13px;
  }
}

/* 985-1200px特殊处理，确保按钮对齐 */
@media (min-width: 985px) and (max-width: 1200px) {
  .announcement-item {
    position: relative;
  }
  
  .announcement-actions {
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    min-width: 70px !important;
    flex-shrink: 0 !important;
    width: auto !important;
    align-self: auto !important;
    flex-direction: row !important;
    align-items: center !important;
  }
  
  .announcement-content {
    padding-right: 90px !important;
    min-height: 120px !important;
  }
  
  .action-btn {
    height: 30px !important;
    width: 30px !important;
    flex-shrink: 0 !important;
  }
  
  .action-btn .el-icon {
    font-size: 13px !important;
  }
}

/* 570-985px特殊处理，覆盖上面的样式 */
@media (min-width: 570px) and (max-width: 985px) {
  .announcement-actions {
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    min-width: 70px !important;
    flex-shrink: 0 !important;
    width: auto !important;
    align-self: auto !important;
    flex-direction: row !important;
    align-items: center !important;
  }
  
  .announcement-content {
    padding-right: 90px !important;
    min-height: 120px !important;
  }
  
  .action-btn {
    height: 30px !important;
    width: 30px !important;
    flex-shrink: 0 !important;
  }
  
  .action-btn .el-icon {
    font-size: 13px !important;
  }
}

/* 小屏幕优化 (570px以下) */
@media (max-width: 569px) {
  .announcement-editor {
    height: 100vh;
    overflow: auto;
  }
  
  .editor-content {
    padding: 10px;
    flex: none;
  }
  
  .main-row {
    margin: 0;
  }
  
  .main-row .el-col {
    margin-bottom: 15px;
  }
  
  .page-header {
    padding: 10px 15px;
  }
  
  .page-title {
    font-size: 1.3rem;
  }
  
  .card-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }
  
  .header-actions {
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
  }
  
  .announcement-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .list-card,
  .form-card {
    height: auto;
    min-height: 300px;
  }
  
  .announcement-list {
    max-height: 400px;
  }
  
  .pagination-container .el-pagination {
    flex-wrap: wrap;
    gap: 10px;
  }
}

@media (max-width: 768px) {
  /* 570-768px之间的额外优化 */
  .announcement-actions {
    gap: 8px;
  }
  
  .action-btn {
    height: 28px;
    width: 28px;
  }
  
  .action-btn .el-icon {
    font-size: 12px;
  }
  
  .add-btn,
  .form-btn,
  .upload-btn {
    height: 32px;
    padding: 6px 12px;
    font-size: 0.8rem;
  }
  
  .add-btn .el-icon,
  .form-btn .el-icon,
  .upload-btn .el-icon {
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .announcement-editor {
    height: 100vh;
    overflow: auto;
  }
  
  .editor-content {
    padding: 5px;
  }
  
  .page-header {
    padding: 8px 10px;
  }
  
  .page-title {
    font-size: 1.1rem;
  }
  
  .card-header h2,
  .card-header h3 {
    font-size: 1.1rem;
  }
  
  .announcement-item {
    padding: 12px;
    margin-bottom: 10px;
  }
  
  .announcement-image {
    height: 120px;
  }
  
  .announcement-title {
    font-size: 1rem;
  }
  
  .announcement-excerpt {
    font-size: 0.9rem;
  }
  
  .action-btn {
    height: 28px;
    width: 28px;
  }
  
  .add-btn,
  .form-btn,
  .upload-btn {
    height: 32px;
    padding: 6px 12px;
    font-size: 0.8rem;
  }
  
  .pagination-container {
    padding: 15px 0;
  }
  
  .rounded-pagination {
    padding: 0 10px;
  }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 600px) {
  .announcement-editor {
    height: 100vh;
    overflow: auto;
  }
  
  .page-header {
    padding: 8px 15px;
  }
  
  .page-title {
    font-size: 1.2rem;
  }
  
  .editor-content {
    padding: 10px;
  }
  
  .list-card,
  .form-card {
    height: auto;
    min-height: 250px;
  }
  
  .announcement-list {
    max-height: 300px;
  }
  
  .announcement-item {
    padding: 12px;
    margin-bottom: 10px;
  }
  
  .announcement-image {
    width: 80px;
    height: 60px;
  }
  
  .announcement-actions {
    gap: 6px;
    min-width: 70px;
    flex-direction: row;
    align-items: center;
  }
  
  .action-btn {
    height: 26px;
    width: 26px;
  }
  
  .add-btn,
  .form-btn,
  .upload-btn {
    height: 30px;
    padding: 6px 10px;
    font-size: 0.75rem;
  }
  
  .pagination-container {
    padding: 10px 0;
  }
}

/* 动画效果 */
@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInFromRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes buttonPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.action-btn:active {
  animation: buttonPulse 0.2s ease-in-out;
}

.list-card {
  animation: slideInFromLeft 0.6s ease-out;
}

.form-card {
  animation: slideInFromRight 0.6s ease-out 0.2s both;
}

/* 卡片阴影效果 */
.el-card {
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: none;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.el-card:hover {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}
</style> 